<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">导入数据</h4>
</div>
<form id="defaultForm" method="post" class="form-horizontal" enctype="multipart/form-data"
      action="/project/indexManage/indexImport_Data">
    <input name="id" style="display: none">
    <div class="modal-body">

        <div class="form-group">
            <label class="col-lg-3 control-label">文件</label>
            <div class="col-lg-5">
                <input type="text" class="form-control" id="filename" name="filename" accept="text/plain"/>
            </div>

            <div class="col-lg-2">

                <button type="button" id="uploadExcel" class="btn btn-success fileinput-button"
                        data-btn-type="selectIcon">打开
                </button>
                <!--<input type="file" id="uploadExcel"  style="position:absolute;top:0;left:0;font-size:34px; opacity:0">-->
            </div>
            <div class="col-lg-2">
                <a href="/project/indexManage/index_exportTemplate"><p style="font-size:16px">模板</p></a>
            </div>
        </div>
    </div>


</form>

<script>

    $("#uploadExcel").upload({
        action: "/project/indexManage/indexImport_Data", //表单提交的地址
        name: "myFile",
        onComplete: function (data) {
            //alert(JSON.stringify(data))
            if (data == "0") {
                alert("Excel导入成功")
            } else if (data == "1"){
                alert("Excel导入失败,请确保(编号的唯一性)")
            }
            $("#modal").modal("hide");
            $("#dataTable").bootstrapTable('refresh', {url: '/project/indexManage/index_data'});
        },
        onSelect: function () {
            //当选择了文件后，关闭自动提交
            this.autoSubmit = false;
            //校验上传的文件名是否满足后缀为.xls或.xlsx
            var regex = /^.*\.(?:xls|xlsx)$/;
            //校验
            if (regex.test($("[name = '" + this.name() + "']").val())) {
                //通过校验
                this.submit();
            } else {
                //未通过
                alert("文件格式不正确，必须以.xls或.xlsx结尾")
            }
        }
    });


</script>
